/*
 * @Description: 
 * @Author: Jimmy
 * @Date: 2023-07-25 20:19:01
 * @LastEditTime: 2023-07-25 20:29:19
 * @LastEditors:  
 */
import { Context, Next } from "koa";
import { callbackData } from "../utils/data.handler";
import { access } from "../logger";

export const verifyPageSize = async(ctx:Context,next:Next)=>{
    let {page=1,size=0} = JSON.parse(JSON.stringify(ctx.query)) || {};
    console.log(page,size)
    let numberPage = Number(page);
    let numberSize = Number(size);
    if(isNaN(numberPage) || isNaN(numberSize)){
        access.info('分页参数格式错误',{page,size})
        console.error('分页参数格式错误',{page,size})
        ctx.app.emit('error',callbackData('1','分页参数格式错误'),ctx);
        return false;
    }
    ctx.request.body.page = numberPage;
    ctx.request.body.size = numberSize
    await next();
}